//
//  WXVistorTableViewController.swift
//  weibo
//
//  Created by 王旭 on 16/4/16.
//  Copyright © 2016年 王旭. All rights reserved.
//

import UIKit

class WXVistorTableViewController: UITableViewController,WXVistorViewDelegate {
    
    var isLogin :Bool = WXUserAccountViewModel.sharedUserAccountViewModel.isLogin
    
    override func viewDidLoad() {
        
        
//        if isLogin {
//            super.viewDidLoad()
//        }else{
//            view = WXVistorView()
//        }
        
        //简化为三目
        isLogin ? super.viewDidLoad() : loadVistorView()
        
        //添加两个NavigationBarButtonItem
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "registerButtonClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "loginButtonClick")

    }
    
    //
    func loadVistorView() {
        view = vistorView
    }
    
    //实现代理方法
    func registerButtonClick() {
        print("注册按钮被点击了")

    }
    
    func loginButtonClick() {
//        print("登录按钮被点击了")
        
        //初始化OAuth登录控制器
        let vc = WXOAuthViewController()
        //modal控制器
        presentViewController(UINavigationController(rootViewController: vc), animated: true, completion: nil)
    }
    





    //懒加载WXVistorView 
    lazy var vistorView : WXVistorView = {
        let vistorView = WXVistorView()
        //遵守代理协议
        vistorView.delegate = self
        return vistorView
    }()


}
